package com.lykj.llw.box.ui.diafrg

import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.lifecycle.lifecycleScope
import com.lykj.lib_base.base.BaseDiaFrg
import com.lykj.lib_base.bus.FlowBus
import com.lykj.lib_base.internal.extfun.clickWithTrigger
import com.lykj.llw.box.databinding.DiafrgIntegralExchangeSuccessBinding
import me.jessyan.autosize.utils.AutoSizeUtils

/**
 * ================================================
 * 积分兑换成功弹窗
 * ================================================
 *
 * @author gosha
 * @date 2023/10/26-13:54
 */
class IntegralExchangeSuccessDiaFrg : BaseDiaFrg() {
    lateinit var binding: DiafrgIntegralExchangeSuccessBinding

    private var mPTB = 0

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DiafrgIntegralExchangeSuccessBinding.inflate(layoutInflater)
        initUI()
        initData()
        setListener()
        return binding.root
    }

    override fun onStart() {
        super.onStart()

        val window = dialog!!.window
        //设置窗口弹出动画
        window!!.setWindowAnimations(0)
        window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        val layoutParams = window.attributes
        layoutParams.apply {
            dimAmount = 0.5f
            gravity = Gravity.CENTER
            width = WindowManager.LayoutParams.WRAP_CONTENT
            height = WindowManager.LayoutParams.WRAP_CONTENT
        }


        if (null != dialog) {
            val dm = DisplayMetrics()
            requireActivity().windowManager.defaultDisplay.getMetrics(dm)
            dialog?.apply {
                setCanceledOnTouchOutside(false)
//                window.setGravity(Gravity.CENTER)
            }
        }
    }

    override fun initUI() {
    }

    open fun setPtb(ptb: Int): IntegralExchangeSuccessDiaFrg {
        this.mPTB = ptb
        return this
    }

    override fun initData() {
        binding.tvPtb.text = " $mPTB 平台币"
    }

    override fun setListener() {
        binding.tvBtnDismiss.clickWithTrigger {
            dismiss()
        }
        binding.tvBtnLook.clickWithTrigger {
            FlowBus.with<String>("updatePtb").post(lifecycleScope, "")
            dismiss()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
    }
}